/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-01-26
 * Time: 20:13
 */
public class ListNode {
       public int val;
       public ListNode next;

        public ListNode() {
            this.val = val;
        }
    public ListNode FindKthToTail(ListNode head,int k) {
        if(head == null) {
            return null;
        }
        ListNode fast = head;
        ListNode slow = head;
        //先走k步
        for(int i=0;i<k;i++) {
            if(fast == null) {
                return null;
            }
            fast = fast.next;
        }
        //fast与slow一起走，当fast为null时返回slow结点
        while(fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }

    public static void main(String[] args) {
        ListNode listNode = new ListNode();
    }
}
